package com.xujiaxin.programme_platform.system;

import com.xujiaxin.programme_platform.system.enumeration.OSEnum;

/*
* 操作系统信息
* */
public class OSInfo {
    private static String OS = System.getProperty("os.name").toLowerCase();

    private static OSInfo _instance = new OSInfo();

    private OSInfo(){}
    
    public static boolean isLinux(){
        return OS.indexOf("linux")>=0;
    }

    public static boolean isMacOS(){
        return OS.indexOf("mac")>=0&&OS.indexOf("os")>0&&OS.indexOf("x")<0;
    }

    public static boolean isMacOSX(){
        return OS.indexOf("mac")>=0&&OS.indexOf("os")>0&&OS.indexOf("x")>0;
    }

    public static boolean isWindows(){
        return OS.indexOf("windows")>=0;
    }

    public static boolean isOS2(){
        return OS.indexOf("os/2")>=0;
    }

    public static boolean isSolaris(){
        return OS.indexOf("solaris")>=0;
    }

    public static boolean isSunOS(){
        return OS.indexOf("sunos")>=0;
    }

    public static boolean isMPEiX(){
        return OS.indexOf("mpe/ix")>=0;
    }

    public static boolean isHPUX(){
        return OS.indexOf("hp-ux")>=0;
    }

    public static boolean isAix(){
        return OS.indexOf("aix")>=0;
    }

    public static boolean isOS390(){
        return OS.indexOf("os/390")>=0;
    }

    public static boolean isFreeBSD(){
        return OS.indexOf("freebsd")>=0;
    }

    public static boolean isIrix(){
        return OS.indexOf("irix")>=0;
    }

    public static boolean isDigitalUnix(){
        return OS.indexOf("digital")>=0&&OS.indexOf("unix")>0;
    }

    public static boolean isNetWare(){
        return OS.indexOf("netware")>=0;
    }

    public static boolean isOSF1(){
        return OS.indexOf("osf1")>=0;
    }

    public static boolean isOpenVMS(){
        return OS.indexOf("openvms")>=0;
    }

    /**
     * 获取操作系统名字
     * @return 操作系统名
     */
    public static OSEnum getOSName(){
        if(isAix()){
            return OSEnum.AIX;
        }else if (isDigitalUnix()) {
            return OSEnum.Digital_Unix;
        }else if (isFreeBSD()) {
            return OSEnum.FreeBSD;
        }else if (isHPUX()) {
            return OSEnum.HP_UX;
        }else if (isIrix()) {
            return OSEnum.Irix;
        }else if (isLinux()) {
            return OSEnum.Linux;
        }else if (isMacOS()) {
            return OSEnum.Mac_OS;
        }else if (isMacOSX()) {
            return OSEnum.Mac_OS_X;
        }else if (isMPEiX()) {
            return OSEnum.MPEiX;
        }else if (isNetWare()) {
            return OSEnum.NetWare_411;
        }else if (isOpenVMS()) {
            return OSEnum.OpenVMS;
        }else if (isOS2()) {
            return OSEnum.OS2;
        }else if (isOS390()) {
            return OSEnum.OS390;
        }else if (isOSF1()) {
            return OSEnum.OSF1;
        }else if (isSolaris()) {
            return OSEnum.Solaris;
        }else if (isSunOS()) {
            return OSEnum.SunOS;
        }else if (isWindows()) {
            return OSEnum.Windows;
        }else{
            return OSEnum.Others;
        }
    }
}
